﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Utilities;

namespace EwmCreater
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }
        private bool isCancel = false;
        private void button1_Click(object sender, EventArgs e)
        {
            string dateStr = DateTime.Now.ToString("yyMMdd");
            pb.Value = 0;
            pb.Maximum = 1000;
            pb.Step = 1;

            for (int i = 1; i <= 1000; i++)
            {
                if (isCancel)
                {
                    lblReport.Text = $"操作取消,目前为止生成{i}个";
                    Application.DoEvents();
                    break;
                }
                lblReport.Text = "正在生成...";
                createBit(2, i, dateStr);
                Application.DoEvents();
                createBit(4, i, dateStr);
                Application.DoEvents();
                createBit(8, i, dateStr);
                Application.DoEvents();
                pb.PerformStep();
            }
            if (isCancel == false)
            {
                lblReport.Text = $"生成完成";
            }
        }
        private void createBit(int value, int index, string dateStr)
        {
            string logoFile = Path.Combine(Environment.CurrentDirectory, "Logo.png");
            string outFile, idCode, ewmCode;
            idCode = $"a{dateStr}{index.ToString("D3")}";
            outFile = Path.Combine(GVar.PngGirl, $"{idCode}.png");
            switch (value)
            {

                case 4:
                    idCode = $"b{dateStr}{index.ToString("D3")}";
                    outFile = Path.Combine(GVar.PngStore, $"{idCode}.png");
                    break;
                case 8:
                    idCode = $"c{dateStr}{index.ToString("D3")}";
                    outFile = Path.Combine(GVar.PngUser, $"{idCode}.png");
                    break;
                default:
                    break;
            }

            //BitPool mdBit;
            //mdBit = new BitPool();

            //mdBit.AddDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            //mdBit.Code = idCode + Guid.NewGuid().ToString("N");
            //mdBit.Value = value;
            //try
            //{
            //    if (mdBit.Insert(x => x.Id))
            //    {
            //        ewmCode = $"http://www.halouwo.cn/html/index.html?value={mdBit.Value}&code={mdBit.Code}";
            //        EwmHelper.Generate(ewmCode, logoFile, outFile);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    LogHelper.Error(ex);
            //}
        }
    }
}
